$(document).ready(function(){
    var step = $.cookie("step");   
    if(step==="starturl"){
        $("#starturl_set").attr("class", "btn btn-primary");
    }
    else{
        $(".start").attr("class", "btn btn-primary");
    }
    $("#starturlsubmit").bind("click", function(){
           var options = {
            success:function(data){
                var dataObj=eval("("+data+")");
                if(dataObj.code===0){
                    window.localtion.href="";
                }else{
                    $("#error").text(data);
                }
            }
           }; 
           $("#starturlform").ajaxSubmit(options);
    });
    $("#domainsubmit").bind("click", function(){
           var options = {
            success:function(data){
                var dataObj=eval("("+data+")");
                if(dataObj.code===0){
                    $.cookie("step", "starturl");
                    window.location.href="spidercreate";
                }else{
                    $(".error").html(dataObj.msg);
                }
            }
           }; 
           $("#domainform").ajaxSubmit(options);
            
    });
    $("#spider_set").click(function(){
       $(".error").html("");
       $("input[type]").attr("value", "");
    })

})

function set_url(){
    var html = $("#seturl").html();
    var htmlre = html.replace(" ","");
    var regix = /starturl(\d+?)/g;
    var id = htmlre.match(regix)
    var last_id = id.pop();//delete last element and return it
    var int_id = regix.exec(last_id);
    var new_id = parseInt(int_id[1]) + 1;
    var new_html = '<input name="starturl' + new_id + '" value="http://" class="form-control" onblur="set_url()" type="text">';
    var all_html = html + "<br />" + new_html;
    $("#seturl").html(all_html);
}

